package adv4;

import java.util.*;

//3：List,Set中必须掌握的方法都要写个例子
public class Example{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        //Set方法例子
        Set s = new HashSet();
        s.add("1a");
        s.add("2b");
        s.add(Math.PI);
        s.add("3c");
        s.add("tiger");
        s.add("tiger");
        System.out.println("个数" + s.size());//长度不包括重复的
        System.out.println(s);
        System.out.println("1====增强for遍历：");
        for (Object o : s) {
            System.out.print(o + "\t");
        }
        System.out.println();
        System.out.println("2====数组遍历：");
        Object[] objects = s.toArray();
        for (int i = 0; i < objects.length; i++) {
            System.out.print(objects[i] + "\t");
        }
        System.out.println();
        System.out.println("3====迭代器遍历：");
        Iterator ir = s.iterator();
        while (ir.hasNext()) {
            System.out.print(ir.next() + "\t");
        }
        System.out.println();
        System.out.println("****************************************");
        //List方法例子
        List l2 = new LinkedList();
        l2.add("dog");
        l2.add("cat");
        l2.add("donkey");
        l2.add("tiger");
        ((LinkedList) l2).addFirst("零");//首位加入
        System.out.println(l2);
        List list = new ArrayList();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add(Math.E);
        list.add("d");
        list.add("e");
        list.add("e");
        System.out.println(list.size());//长度包括重复的
        Object o1 = list.get(5);
        System.out.println("第六个是" + o1);//位置查找
        System.out.println(">>>>>>>>>>>>>>>>>>>>");
        list.add(1, "tiger");//插入位置
        System.out.println(list);
        System.out.println(">>>>>>>>>>>>>>>>>");
        for (int i = 0; i < list.size(); i++) {//遍历
            System.out.print(list.get(i) + "  ");
        }
        System.out.println("\n增强for:");
        for (Object oo : list) System.out.print(oo + "  ");
        System.out.println("\n>>>>>>>>>>>>>>>>>>>>");
        System.out.println("是否包含：");
        String str = in.next();
        System.out.print(list.contains(str) + "  ");
        System.out.println(">>>>>>>>>>>>>>>>>>>>");
        System.out.println("删除位置：");
        Object remove = list.remove(in.nextInt());
        System.out.println("删除后：" + list);
    }
}